home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / cardpkg_1.3.lha / CardPkg / Hello_V.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-19  |  4.4 KB  |  159 lines

  1. /************************************************************
  2.  
  3.     TML's C Language Card Image Package  v1.1
  4.  
  5.     January, 1993
  6.     Todd M. Lewis             (919) 776-7386
  7.     2601 Piedmont Drive
  8.     Sanford, NC  27330-9437
  9.     USA
  10. ************************************************************/
  11. #include <stdlib.h>
  12. #include <exec/types.h>
  13. #include <intuition/intuition.h>
  14. #include <intuition/intuitionbase.h>
  15.  
  16. #ifdef AZTEC_C
  17.   #include <functions.h>
  18.   #define __far
  19. #endif
  20. #ifdef __SASC
  21.   #include <clib/alib_protos.h>
  22.   #include <clib/intuition_protos.h>
  23.   #include <clib/graphics_protos.h>
  24.   #include <clib/dos_protos.h>
  25.   #include <clib/exec_protos.h>
  26. #endif
  27.  
  28. #include "CardVImages.h"
  29. #include "Cards.h"
  30.  
  31. extern UWORD       RangeRand( ULONG );
  32. extern ULONG __far RangeSeed;
  33.  
  34. struct IntuitionBase *IntuitionBase;
  35. struct GfxBase       *GfxBase;
  36.  
  37. #define INTUITION_REV 28
  38. #define GRAPHICS_REV  28
  39.  
  40. struct Window *Window;
  41. struct NewWindow newwindow =
  42.   {
  43.         20,8,   /* window XY origin relative to TopLeft of screen */
  44.         569,190, /* window width and height */
  45.         0,1,     /* detail and block pens */
  46.         CLOSEWINDOW,    /* IDCMP flags */
  47.         WINDOWDRAG  | WINDOWDEPTH |
  48.         WINDOWCLOSE | ACTIVATE    | NOCAREREFRESH,  /* other window flags */
  49.         NULL,   /* first gadget in gadget list */
  50.         NULL,   /* custom CHECKMARK imagery */
  51.         (UBYTE *)" Testing Card Images ",       /* window title */
  52.         NULL,   /* custom screen pointer */
  53.         NULL,   /* custom bitmap */
  54.         5,5,    /* minimum width and height */
  55.         0xffff,0xffff,  /* maximum width and height */
  56.         WBENCHSCREEN    /* destination screen type */
  57.   };
  58.  
  59. CardID_t cards[56]; /* 52 "normal" and 4 "special" cards */
  60.  
  61. void clear_a_card( int i ) /* Remove a single card. */
  62.   {
  63.     ShowVCard( Window->RPort,
  64.                CARD_NONE,
  65.                Window->BorderLeft + 2 + i % 13 * (CARD_V_WIDTH+5),
  66.                Window->BorderTop  + 2 + i / 13 * (CARD_V_HEIGHT+2) );
  67.   }
  68.  
  69. void clear_cards( void )  /* Clear all the cards. */
  70.   {
  71.     int i;
  72.     for (i=0; i<56; i++)
  73.       {
  74.         clear_a_card( i );
  75.         Delay( 5L );
  76.       }
  77.   }
  78.  
  79. void show_a_card( int i )  /* Shows a single card ( cards[i] ). */
  80.   {
  81.     ShowVCard( Window->RPort,
  82.                cards[i],
  83.                Window->BorderLeft + 2 + i % 13 * (CARD_V_WIDTH+5),
  84.                Window->BorderTop  + 2 + i / 13 * (CARD_V_HEIGHT+2) );
  85.   }
  86.  
  87. void show_cards( void )  /* Show all the cards. */
  88.   {
  89.     int i;
  90.     for (i=0; i<56; i++)
  91.       show_a_card( i );
  92.   }
  93.  
  94. void bubble_sort_and_show( void )
  95.   {
  96.     CardID_t tmp;
  97.     int i,j;
  98.  
  99.     for (j=0 ;j<56; j++)
  100.       for (i=0; i<55; i++)
  101.         if ( cards[i] > cards[i+1] )  /* CardID_t's can be compared. */
  102.           {
  103.             tmp = cards[i];
  104.                   cards[i] = cards[i+1];
  105.                              cards[i+1] = tmp;
  106.             show_a_card( i );
  107.             show_a_card( i+1);
  108.             WaitTOF();
  109.             WaitTOF();   /* Slow it down enough to see the swaps! */
  110.           }
  111.   }
  112.  
  113. main()
  114.   {
  115.    IntuitionBase = (struct IntuitionBase *)
  116.       OpenLibrary("intuition.library", (long)INTUITION_REV);
  117.    if(IntuitionBase == NULL)
  118.       exit(FALSE);
  119.  
  120.    GfxBase = (struct GfxBase *)
  121.       OpenLibrary("graphics.library", (long)GRAPHICS_REV);
  122.    if(GfxBase == NULL)
  123.       exit(FALSE);
  124.  
  125.    if(( Window = (struct Window *) OpenWindow(&newwindow)) == NULL)
  126.       exit(FALSE);
  127.  
  128.    /* RangeRand() uses RangeSeed.  We need to set RangeSeed to something  */
  129.    /* different each time we run.  Here's one way to do it...     */
  130.  
  131.    CurrentTime( &RangeSeed, &RangeSeed );
  132.  
  133.    if ( CardRange( &cards[ 0], 52, sizeof(cards[0]), SUIT_SPADES,  1 ) &&   /* Normal cards  */
  134.         CardRange( &cards[52],  4, sizeof(cards[0]), SUIT_SPECIAL, 1 )    ) /* Special cards */
  135.      {
  136.        show_cards();
  137.        SetWindowTitles( Window,"Here are the cards!","Testing Vertical Cards");
  138.        Delay( 250 );
  139.  
  140.        Shuffle( cards, 56, sizeof(cards[0]) );
  141.        show_cards();
  142.        SetWindowTitles( Window,"The Cards are Shuffled.",(UBYTE *)0xffffffff);
  143.        Delay( 250 );
  144.  
  145.        SetWindowTitles( Window," Let's sort them with a Bubble sort.",(UBYTE *)0xffffffff);
  146.        bubble_sort_and_show();
  147.  
  148.        SetWindowTitles( Window,"<--Close me, I'm done.",(UBYTE *)0xffffffff);
  149.      }
  150.  
  151.     Wait(1L << Window->UserPort->mp_SigBit);
  152.     clear_cards();
  153.     CloseWindow (                   Window        );
  154.     CloseLibrary( (struct Library *)IntuitionBase );
  155.     CloseLibrary( (struct Library *)GfxBase       );
  156.  
  157.     return 0;
  158.   }
  159.